.text

.extern clock_interrupt_handler
.extern keymap_handler
.extern exception_handler
.extern rtc_interrupt_handler

.globl rtc_handler_entry
rtc_handler_entry:
    call rtc_interrupt_handler
    iretq

.globl keymap_handler_entry
keymap_handler_entry:
    iretq

// 进入中断时的栈结构
// rip
// cs
// rflags
.macro INTERRUPT_HANDLER idx
.globl interrupt_handler_\idx
interrupt_handler_\idx:
    // r8: eflags
    movq 8*2(%rsp), %r8
    // rcx: cs
    movq 8(%rsp), %rcx
    // rdx: rip
    movq (%rsp), %rdx
    // rsi: esp
    movq %rsp, %rsi
    // rdi: idt_index
    movq \idx, %rdi
    call exception_handler
    iretq
.endm

INTERRUPT_HANDLER 0x00
INTERRUPT_HANDLER 0x01
INTERRUPT_HANDLER 0x02
INTERRUPT_HANDLER 0x03
INTERRUPT_HANDLER 0x04
INTERRUPT_HANDLER 0x05
INTERRUPT_HANDLER 0x06
INTERRUPT_HANDLER 0x07
INTERRUPT_HANDLER 0x08
INTERRUPT_HANDLER 0x09
INTERRUPT_HANDLER 0x0a
INTERRUPT_HANDLER 0x0b
INTERRUPT_HANDLER 0x0c
INTERRUPT_HANDLER 0x0d
INTERRUPT_HANDLER 0x0e
INTERRUPT_HANDLER 0x0f
INTERRUPT_HANDLER 0x10
INTERRUPT_HANDLER 0x11
INTERRUPT_HANDLER 0x12
INTERRUPT_HANDLER 0x13
INTERRUPT_HANDLER 0x14
INTERRUPT_HANDLER 0x15
INTERRUPT_HANDLER 0x16
INTERRUPT_HANDLER 0x17
INTERRUPT_HANDLER 0x18
INTERRUPT_HANDLER 0x19
INTERRUPT_HANDLER 0x1a
INTERRUPT_HANDLER 0x1b
INTERRUPT_HANDLER 0x1c
INTERRUPT_HANDLER 0x1d
INTERRUPT_HANDLER 0x1e
INTERRUPT_HANDLER 0x1f

.globl interrupt_handler_table
interrupt_handler_table:
    .quad interrupt_handler_0x00
    .quad interrupt_handler_0x01
    .quad interrupt_handler_0x02
    .quad interrupt_handler_0x03
    .quad interrupt_handler_0x04
    .quad interrupt_handler_0x05
    .quad interrupt_handler_0x06
    .quad interrupt_handler_0x07
    .quad interrupt_handler_0x08
    .quad interrupt_handler_0x09
    .quad interrupt_handler_0x0a
    .quad interrupt_handler_0x0b
    .quad interrupt_handler_0x0c
    .quad interrupt_handler_0x0d
    .quad interrupt_handler_0x0e
    .quad interrupt_handler_0x0f
    .quad interrupt_handler_0x10
    .quad interrupt_handler_0x11
    .quad interrupt_handler_0x12
    .quad interrupt_handler_0x13
    .quad interrupt_handler_0x14
    .quad interrupt_handler_0x15
    .quad interrupt_handler_0x16
    .quad interrupt_handler_0x17
    .quad interrupt_handler_0x18
    .quad interrupt_handler_0x19
    .quad interrupt_handler_0x1a
    .quad interrupt_handler_0x1b
    .quad interrupt_handler_0x1c
    .quad interrupt_handler_0x1d
    .quad interrupt_handler_0x1e
    .quad interrupt_handler_0x1f